<?php 
	ini_set("include_path", ".:../:./includes:../includes");
	//error_reporting(0);
	require_once("includes/constants.php");
	require_once("includes/database.php");
	require_once("includes/common.php");
	require_once("includes/template.php"); 
	head("Manage Orders");
	
	$all=false;
	$readyToShip=false;
	$shipped=false;
	$charged=false;
	
	// unset($_SESSION[ORDERS]);

		if ($_REQUEST['operation'] == "readyToShip") {
			$readyToShip = true;
			$_SESSION[ORDERS] = getShippableOrders();  
		}
		else if ($_REQUEST['operation'] == "shipped") {		
			$shipped = true;
			$_SESSION[ORDERS] = getShippedOrders(); 
		}
		else if ($_REQUEST['operation'] == "charged") {		
			$charged = true;
			$_SESSION[ORDERS] = getChargedOrders(); 
		}	
		else {//all
	 		$all = true;
			$_SESSION[ORDERS] = getAllOrders(); 			
		}	
	 	
	
?>
<div style="padding: 20px 20px 20px 20px; ">
	<label for="operation">View</label>
	<select id="operation" name="operation" onchange="javascript:document.mainform.action='manageOrders.php';document.mainform.submit();" >
	
		<option value="readyToShip" 
			<?php if ($readyToShip) echo "selected='selected'"; ?>
		>Ready To Ship</option>
		<option value="shipped"
			<?php if ($shipped) echo "selected='selected'"; ?>
		>Shipped</option>
		<option value="charged"
			<?php if ($charged) echo "selected='selected'"; ?>	
		>Charged</option>
		<option value="all"
			<?php if ($all) echo "selected='selected'"; ?>	
		>All</option>
	</select>
</div>
<?php if (!isset($_SESSION[ORDERS])) { ?>
	There are no matching orders.
<?php } else { ?>

			
			
<table cellspacing="5px"  width="100%">	
	<tr>
		<td>
			&nbsp;
		</td>
		<td class="button1">
			Order ID
		</td>		
		<td class="button1">
			Customer
		</td>				
		<td class="button1">
			Due Date
		</td>			
		<td class="button1">
			Order Total
		</td>		
		<td class="button1">
			Order Status
		</td>	
		<td class="button1">
			Payment Status
		</td>			
				
	</tr>
	<?php 
		$count = count($_SESSION[ORDERS]);?>
		<input type="hidden" name="orderCount" id="orderCount" value=<?php echo $count; ?> />
	<?php 	foreach ($_SESSION[ORDERS] as $index =>$order) {
	?>
	
	<tr >
		<td align="right">
			<input type=radio id="selectedOrder<?php echo $index; ?>" name="selectedOrder" value="<?php echo $index;?>" /> 
		</td>
		<td class="button2">
			<?php echo $_SESSION[ORDERS][$index]['o_order_id']; ?>
		</td>		
		<td class="button2">
			<?php echo $_SESSION[ORDERS][$index]['a_contact_name']; ?>
		</td>
		<td class="button2">
			<?php echo $_SESSION[ORDERS][$index]['o_due_date']; ?>
		</td>
		<td class="button2">
			<?php echo $_SESSION[ORDERS][$index]['o_total_price']; ?>
		</td>
		<td class="button2">
			<?php echo $_SESSION[ORDERS][$index]['o_order_status']; ?>
		</td>
		<td class="button2">
			<?php echo $_SESSION[ORDERS][$index]['o_payment_status']; ?>
		</td>		
	</tr>	
	<?php 	
		}
	?>
</table>
<?php } ?>

<?php 

	if ($all || $charged) {
		foot("VIEW","viewOrder.php");		
	}
	else if ($readyToShip) {
		foot("VIEW","viewOrder.php", 
			"PRINT", "printOrder.php", 
			"SHIP", "shipOrder.php",
			"PRINT ALL", "printOrder.php?bulk=true", 
			"SHIP ALL", "shipOrder.php?bulk=true" 		
		);
	}
	else if ($shipped) {
		foot("VIEW","viewOrder.php", 
			"CHARGE", "chargeOrder.php", 
			"CHARGE ALL", "chargeOrder.php?bulk=true"
		);
	}
		

?>

	
